//
//  MZUserInfo.swift
//  TinyShopKeeper_Swift
//
//  Created by huangtao on 16/5/17.
//  Copyright © 2016年 fish. All rights reserved.
//
import Foundation

class MZUserInfo: Reflect {

    //单例
    static let userInfo = MZUserInfo()
    internal required init() {
        
    }
    
    // 店铺账户名登陆账号
//    var shopAccount:String?
//    // 员工登陆账号
//    var userAccount:String?
//    // 员工登陆密码
//    var userPassword:String?
    //token
    var accessToken:String?
    // 账号登陆进来存在的所有商铺
    var userShop:ShopModel?
    // 登录员工id
    var mgrBaseId:String?
    // 员工所属店铺id
    var mgrShopId:String?
    //是否已经登陆
    var loginSign:Bool = false
    
    //返回所有id
    func allShopID() -> String{
        
        var shopIDs:[String] = [String]()
        //当前登录id
        shopIDs.append((UserInfo.userShop?.shop_id)!)
        //子店Id
        let shop = UserInfo.userShop
        
        if let subs = (shop?.subs){
            for ShopMode in subs{
                shopIDs.append(ShopMode.shop_id!)
            }
        }
        
        let shopArray = shopIDs as NSArray//转类型
        let str:NSString = shopArray.componentsJoinedByString(",")//分割
        
        return str as String
        
    }
    
    // 根据shopID返回店铺名称
    func shopNameById(shopId:String) -> String {
        let shop = UserInfo.userShop
        if let subs = (shop?.subs) {
            for shopModel in subs {
                if shopModel.shop_id! == shopId {
                    return shopModel.shop_name!
                }
            }
        }
        return (shop?.shop_name)!
    }
    

    
}
